import { Breadcrumb, Button, Space, Col, Row, message } from 'antd';
import React, { FC } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
import { PageContainer } from '@/component/page-container';
import TransferInfo from './transferInfo';
import styles from './index.less';
import { transactionAudit } from '@/service/student/instudent';
import { getPathRoot } from '@/utils';
import { getWorkFlowStatus } from '@/service';
import Prompt from '@/view/component/prompt';

const Groups: FC = () => {
  const navigate = useNavigate();
  const location = useLocation();
  const [isAudit, setIsAudit] = React.useState<boolean>(false);

  const init = async () => {
    const res = await getWorkFlowStatus(location.state.process_instance_id);
    if (res.success) {
      setIsAudit(['pending', 'progressing'].includes(res.data));
    }
  };
  React.useEffect(() => {
    init();
  }, []);
  return (
    <PageContainer
      header={
        <Breadcrumb
          items={[
            { title: '转学管理', onClick: () => navigate(`${getPathRoot()}/instudent/transfer`) },
            { title: '审批' },
          ]}
        />
      }
    >
      <TransferInfo hideLogs={false} />
      <Row className={styles.transferapprovebtnpanal}>
        <Col span="24">
          <Space>
            <Button onClick={() => navigate(`${getPathRoot()}/instudent/transfer`)}>返回</Button>
            {isAudit ? (
              <>
                {/* <Button
                  type="primary"
                  onClick={() => {
                    Modal.confirm({
                      title: '审批拒绝',
                      content: `是否审批拒绝?`,
                      onOk: async () => {
                        const r = await transactionAudit(location.state.id, 'refuse', '拒绝');
                        if (r.success) {
                          message.success('操作成功');
                          navigate(`${getPathRoot()}/instudent/transfer`);
                        } else {
                          message.error(r.message);
                        }
                      },
                    });
                  }}
                >
                  拒绝
                </Button> */}
                <Prompt
                  title="审核拒绝"
                  inputLabel="审核意见"
                  onOk={async (cnt: string) => {
                    const r = await transactionAudit(location.state.process_instance_id, 'refuse', '拒绝');
                    if (r.success) {
                      message.success('操作成功');
                      init();
                      return true;
                      //navigate(`${getPathRoot()}/instudent/transfer`);
                    }
                    //message.error(r.message || r.details);
                    return false;
                  }}
                >
                  拒绝
                </Prompt>
                {/* <Button
                  type="primary"
                  onClick={() => {
                    Modal.confirm({
                      title: '审批通过',
                      content: `是否审批通过?`,
                      onOk: async () => {
                        const r = await transactionAudit(location.state.process_instance_id, 'pass', '通过');
                        if (r.success) {
                          message.success('操作成功');
                          navigate(`${getPathRoot()}/instudent/transfer`);
                        } else {
                          message.error(r.message);
                        }
                      },
                    });
                  }}
                >
                  通过
                </Button> */}
                <Prompt
                  title="审核通过"
                  inputLabel="审核意见"
                  type="primary"
                  onOk={async (cnt: string) => {
                    const r = await transactionAudit(location.state.process_instance_id, 'pass', cnt);
                    if (r.success) {
                      message.success('操作成功');
                      init();
                      return true;
                      //navigate(`${getPathRoot()}/instudent/transfer`);
                    }
                    //message.error(r.message || r.details);
                    return false;
                  }}
                >
                  通过
                </Prompt>
              </>
            ) : (
              ''
            )}
          </Space>
        </Col>
      </Row>
    </PageContainer>
  );
};

export default Groups;
